import 'package:fate_blind_box/chat_view/ahu_text.dart';
import 'package:fate_blind_box/chat_view/chat_net_image.dart';
import 'package:fate_blind_box/config/app_style.dart';
import 'package:fate_blind_box/routes/page_route_names.dart';
import 'package:fate_blind_box/utils/default/widget_extension_utils.dart';
import 'package:fate_blind_box/widget/meet_appbar.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:qr_flutter/qr_flutter.dart';
import 'logic.dart';

class MemberListPage extends GetView<MemberListLogic> {
  const MemberListPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: '#337F69D9'.stringToColor,
        title: const AhuText(
          text: '员工管理',
          fontSize: 18,
          fontWeight: FontWeight.w600,
        ),
        centerTitle: true,
        leading: IconButton(
            onPressed: () {
              Navigator.of(context).pop();
            },
            icon: Icon(
              Icons.arrow_back_ios,
              color: '#333333'.stringToColor,
            )),
        flexibleSpace: PreferredSize(
            preferredSize: const Size(double.infinity, kToolbarHeight),
            child: Container(
              decoration: BoxDecoration(
                  gradient: LinearGradient(
                colors: [
                  '#337F69D9'.stringToColor,
                  '#FFFFFF'.stringToColor,
                ],
                begin: Alignment.topCenter,
                end: Alignment.bottomCenter,
              )),
            )),
      ),
      backgroundColor: '#EDEDED'.stringToColor,
      body: Column(
        children: [
          InkWell(
            onTap: () => Get.toNamed(PageRouteNames.memberAdd,
                    arguments: controller.state.matchmakerId)
                ?.then((value) {
              controller.onRefresh();
            }),
            child: Container(
              margin: EdgeInsets.only(top: 2.w),
              padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 14.w),
              height: 74.w,
              color: Colors.white,
              child: Row(
                children: [
                  Image.asset(
                    'images/logo.png',
                    width: 50.w,
                    height: 50.w,
                  ),
                  SizedBox(width: 8.w),
                  Expanded(
                      child: AhuText(
                    text: '添加员工',
                    color: '#3A3A3A'.stringToColor,
                    fontSize: 16,
                  )),
                  Image.asset(
                    'images/rignt.png',
                    width: 9.w,
                    height: 15.w,
                  )
                ],
              ),
            ),
          ),
          Expanded(
            child: Obx(() {
              return SmartRefresher(
                controller: controller.state.refreshController,
                onRefresh: controller.onRefresh,
                child: ListView.separated(
                    padding: EdgeInsets.only(
                        top: 8.w, bottom: ScreenUtil().bottomBarHeight + 44),
                    itemBuilder: (context, index) {
                      return content(index);
                    },
                    separatorBuilder: (context, index) {
                      return Container(
                        color: '#EDEDED'.stringToColor,
                        height: 8.w,
                      );
                    },
                    itemCount: controller.state.memberList.length),
              );
            }),
          ),
        ],
      ),
    );
  }

  Widget content(index) {
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 0.w),
      height: 72.w,
      color: Colors.white,
      child: Row(
        children: [
          // ChatNetImage(
          //   imageUrl: 'imageUrl',
          //   width: 50.w,
          //   height: 50.w,
          //   radius: 5.w,
          // ),
          Image.asset(
            'images/member_header.png',
            width: 50.w,
            height: 50.w,
          ),
          SizedBox(width: 8.w),
          Expanded(
              child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              AhuText(
                text: '${controller.state.memberList[index].employeeName}',
                fontSize: 16,
                color: '#3A3A3A'.stringToColor,
              ),
              SizedBox(height: 3.w),
              Container(
                color: '#19FF8223'.stringToColor,
                child: Row(
                  mainAxisSize: MainAxisSize.min,
                  children: [
                    SizedBox(width: 3.w),
                    Image.asset(
                      'images/tuijian.png',
                      width: 12.w,
                      height: 12.w,
                    ),
                    SizedBox(width: 5.w),
                    AhuText(
                      text: '总推荐量',
                      fontSize: 12,
                      color: '#A7A7A7'.stringToColor,
                    ),
                    AhuText(
                      text: '${controller.state.memberList[index].employeeNum}',
                      fontSize: 20,
                      color: '#FF8223'.stringToColor,
                    ),
                    SizedBox(width: 12.w),
                  ],
                ),
              )
            ],
          )),
          Container(
            width: 30.w,
            height: 30.w,
            decoration: BoxDecoration(
              color: '#EEEBEB'.stringToColor,
              borderRadius: BorderRadius.circular(4.w),
            ),
            child: QrImageView(
              padding: EdgeInsets.all(3.w),
              data: 'data',
              version: QrVersions.auto,
            ),
          ),
          SizedBox(width: 8.w),
          Image.asset(
            'images/rignt.png',
            width: 9.w,
            height: 15.w,
          )
        ],
      ),
    ).clickAction(tapAction: () => Get.toNamed(PageRouteNames.memberCode,arguments: controller.state.memberList[index]));
  }
}
